package com.mvc.service.impl;

import java.io.File;

import com.jfinal.plugin.activerecord.Page;
import com.jfinal.upload.UploadFile;
import com.mvc.model.Notice;
import com.mvc.model.Version;
import com.mvc.request.ReqPage;
import com.mvc.request.ReturnData;
import com.mvc.response.RspPage;
import com.mvc.service.SysService;

/***
 * 系统
 * 
 * @author Swer
 * 
 */
public class SysServiceImpl implements SysService {
	/***
	 * 文件上传
	 * 
	 * @param req
	 * @return
	 */
	public ReturnData<String> updateFile(UploadFile uploadFile) {

		if(uploadFile == null)
		{
			return new ReturnData<String>("",500,"请求参数不完整");
		}
		File file = uploadFile.getFile();
		if (file == null)
		{
			return new ReturnData<String>("",202,"上传失败");
		}
		
		return new ReturnData<String>(file.getName(),200,"上传成功");
	}
	

	/***
	 * 版本检查
	 * 
	 * @param req
	 * @return
	 */
	public ReturnData<Version> checkVesion() {
		Version vesion = Version.dao.getVesion();
		return new ReturnData<Version>(vesion,200,"OK");
	}

	/***
	 * 消息公告
	 * 
	 * @param req
	 * @return
	 */
	public 	ReturnData<RspPage<Notice>> queryPage(ReqPage req) {
		Page<Notice> page = Notice.dao.getPage(req.getNowPage(),req.getPageSize());
		RspPage<Notice> rspPage = new RspPage<Notice>();
		rspPage.setList(page.getList());
		rspPage.setNowPage(req.getNowPage());
		rspPage.setTotalPage(page.getTotalPage());
		return new ReturnData<RspPage<Notice>>(rspPage,200,"OK");
	}

}
